<template>
	
	<view class="components-select">
	
	  <!-- 顶部自定义导航 -->
	  <tn-nav-bar fixed>定制手工单</tn-nav-bar>
	
	  <!-- 页面内容 -->
	  <view class="warp">
		  
		<view class="title">信息填写：</view>
		<view class="storeChoice">
			<span class="must">*</span>预约店铺：<span>咸宁-天洁店</span>
		</view>
	
		<dynamic-demo-template ref="demoTemplate" :tips="tips"  :full="false" @click="click">
			<view class="roomChoice" @click="showSelect">
				<view class="tn-flex tn-flex-row-center"><tn-button style="background-color: white;"><span class="must">*</span>预约房间：</tn-button></view>
				<view class="select-result" style="display: flex; flex-direction: row;">
					{{ result }} <view class="tn-icon-down" style="margin-top: 6rpx;"></view>
				</view>
			</view>
			
		</dynamic-demo-template>
		
		<view class="login__info__item__input tn-flex tn-flex-direction-row tn-flex-nowrap tn-flex-col-center tn-flex-row-left" style="margin-left: 30rpx; margin-top: 18rpx;">
		    <span class="must">*</span>预约电话：
		    <view class="login__info__item__input__content">
				<input maxlength="20" placeholder-class="input-placeholder"/>
		    </view>
		</view>
	    
	    
	
		<view class="timeChoice">
			<view >
			  <picker mode="multiSelector" :value="multiIndex" :range="multiRange" @change="onMultiChange">
				<view class="picker">
				  开始时间：{{ formattedDateTime }}
				</view>
			  </picker>
			</view>
			
			<view >
			  <picker mode="multiSelector" :value="multiIndex" :range="multiRange" @change="onMultiChange">
				<view class="picker">
				  结束时间：{{ formattedDateTime }}
				</view>
			  </picker>
			</view>	
		</view>
		
		<view class="overBtn">
			<view class="btn-ensure" hover-class="tn-hover">取消</view>
			<view class="btn-cancle" hover-class="tn-hover">确定</view>
		</view>
	  </view>
	  
	  <!-- select -->
	  <tn-select
	    v-model="show"
	    :mode="mode"
	    title="请选择房间号"
	    :list="list"
	    @cancel="cancelSelect"
	    @confirm="confirmSelect">
	  </tn-select>
	
	</view>	


 
</template>
 
<script>
 export default {
  data() {
    const now = new Date();
    return {
	  result: '选择预约房间',
	  show: false,
	  mode: 'single',
	  list: [
	    {
	      value: 1,
	      label: '哆啦A梦'
	    },
	    {
	      value: 2,
	      label: '大熊'
	    },
	    {
	      value: 3,
	      label: '小夫'
	    },
	    {
	      value: 4,
	      label: '静香'
	    },
	    {
	      value: 5,
	      label: '胖虎'
	    },
	    {
	      value: 6,
	      label: '大星'
	    },
	  ],
      multiIndex: [
        now.getFullYear() - 1900, // 年份
        now.getMonth(),           // 月份 (0-11)
        now.getDate() - 1,        // 日期 (1-31，减1以用于索引)
        now.getHours(),           // 小时 (0-23)
        now.getMinutes(),         // 分钟 (0-59)
      ],
      multiRange: this.getMultiRange()
    };
  },
  computed: {
    formattedDateTime() {
      const year = this.multiRange[0][this.multiIndex[0]];
      const month = String(this.multiRange[1][this.multiIndex[1]]).padStart(2, '0');
      const day = String(this.multiRange[2][this.multiIndex[2]]).padStart(2, '0');
      const hour = String(this.multiRange[3][this.multiIndex[3]]).padStart(2, '0');
      const minute = String(this.multiRange[4][this.multiIndex[4]]).padStart(2, '0');
 
      return `${year}-${month}-${day} ${hour}:${minute}`;
    }
  },
  methods: {
	 goIndex() {
	 	uni.navigateBack({
	 		delta:1
	 	});
	 },
    getMultiRange() {
      let yearRange = [];
      let monthRange = [];
      let dayRange = [];
      let hourRange = [];
      let minuteRange = [];
      
      // 生成年月日时分秒的数组
      for (let i = 1900; i <= 2100; i++) yearRange.push(i);
      for (let i = 1; i <= 12; i++) monthRange.push(i);
      for (let i = 1; i <= 31; i++) dayRange.push(i);
      for (let i = 0; i <= 23; i++) hourRange.push(i);
      for (let i = 0; i <= 59; i++) minuteRange.push(i);
      
      return [yearRange, monthRange, dayRange, hourRange, minuteRange];
    },
    onMultiChange(e) {
      this.multiIndex = e.detail.value;
    },
	//选择框
	click(event) {
	  this[event.methods] && this[event.methods](event)
	},
	// 弹出Select
	showSelect(event) {
	  this.openSelect()
	},
	cancelSelect(event) {
	  this.$tn.message.toast('未选择房间！')
	},
	// 点击确认按钮
	confirmSelect(event) {
	  console.log(event);
	  switch (this.mode) {
	    case 'single':
	      this.result = event[0]['label']
	      break
	    case 'multi':
	      this.result = ''
	      if (event.length) {
	        event.map((item, index) => {
	          if (index !== 0) this.result += ' - ' 
	          this.result += item.label
	        })
	      }
	      break
	    case 'multi-auto':
	      this.result = ''
	      if (event.length) {
	        event.map((item, index) => {
	          if (index !== 0) this.result += ' - ' 
	          this.result += item.label
	        })
	      }
	      break
	  }
	},
	
	// 打开Select
	openSelect() {
	  this.show = true
	},
	
  }
};
</script>
 
<style lang="scss" scoped>
  @import '@/static/css/templatePage/custom_nav_bar.scss';
  
/deep/ .input-placeholder {
	color: black;
}
.must{
	color: red;
}
.goback{
	width: 40rpx;
	height: 40rpx;
	color: black;
	font-size: larger;
}
.title{
	margin-left: 20rpx;
	font-size: 50rpx;
}
.warp{
	height: 900rpx;
	width: 84%;
	margin-top: 200rpx;
	margin-left: 8%;
	display: flex;
	flex-direction: column;
	justify-content: space-between;
	padding-top: 30rpx;
	padding-bottom: 20rpx;
	border-radius: 40rpx;
	box-shadow: 0px 5px 25px 0px rgba(0, 3, 72, 0.1);
	background-color: #ffffff;
}
.storeChoice{
	height: 50rpx;
	margin-left: 30rpx;
	margin-top: 60rpx;
}
.roomChoice{
	display: flex;
	flex-direction: row;
	margin-top: 20rpx;
}
.timeChoice{
	width: 90%;
	height: 200rpx;
	margin-left: 5%;
	margin-top: 40rpx;
	display: flex;
	flex-direction: column;
	justify-content: space-around;
	position: relative;
}
.picker {
  padding: 10px;
  margin-top: 40rpx;
  background-color: #4E9B52;
  text-align: center;
  color: white;
  border-radius: 20rpx;
}
.select-result {
    padding: 10rpx 30rpx;
    text-align: center;
	position: absolute;
	left: 210rpx;
}
.overBtn{
	display: flex;
	flex-direction: row;
	justify-content: space-around;
	padding-top: 80rpx;
	padding-bottom: 40rpx;
}
.btn-cancle{
		height: 80rpx;
		width: 230rpx;
		font-size: 14px;
		/* #1AAD19 #CCAC82*/
		background-color: #4E9B52;
		color: #fff;
		border: 0px;
		border-radius: 35rpx;
		/* width: 100%; */
		display: flex;
		align-items: center;
		justify-content: center;
}
.btn-ensure{
		height: 80rpx;
		width: 230rpx;
		font-size: 14px;
		/* #1AAD19 #CCAC82*/
		color: #4E9B52;
		border: 2px solid #4E9B52;
		border-radius: 35rpx;
		/* width: 100%; */
		display: flex;
		align-items: center;
		justify-content: center;
}
</style>

